
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>变量作用域与解构赋值 · JavaScript学习</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Veng">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="函数3.html" />
    
    
    <link rel="prev" href="函数的扩展.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="基础.html">
            
                <a href="基础.html">
            
                    
                    基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="变量.html">
            
                <a href="变量.html">
            
                    
                    数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="let和const命令.html">
            
                <a href="let和const命令.html">
            
                    
                    let和const命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="数值.html">
            
                <a href="数值.html">
            
                    
                    数值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="字符串.html">
            
                <a href="字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="对象.html">
            
                <a href="对象.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="数组.html">
            
                <a href="数组.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="Symbol.html">
            
                <a href="Symbol.html">
            
                    
                    Symbol
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.8.1" data-path="函数的扩展.html">
            
                <a href="函数的扩展.html">
            
                    
                    函数的扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.8.2" data-path="变量的解构赋值.html">
            
                <a href="变量的解构赋值.html">
            
                    
                    变量作用域与解构赋值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.3" data-path="函数3.html">
            
                <a href="函数3.html">
            
                    
                    方法函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4" data-path="高阶函数.html">
            
                <a href="高阶函数.html">
            
                    
                    高阶函数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.8.4.1" data-path="map-reduce.html">
            
                <a href="map-reduce.html">
            
                    
                    map/reduce
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4.2" data-path="filter.html">
            
                <a href="filter.html">
            
                    
                    filter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4.3" data-path="sort.html">
            
                <a href="sort.html">
            
                    
                    sort
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.4.4" data-path="array其他方法.html">
            
                <a href="array其他方法.html">
            
                    
                    array其他方法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.8.5" data-path="闭包.html">
            
                <a href="闭包.html">
            
                    
                    闭包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.6" data-path="箭头函数.html">
            
                <a href="箭头函数.html">
            
                    
                    箭头函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.7" data-path="../浏览器/Promise.html">
            
                <a href="../浏览器/Promise.html">
            
                    
                    Promise
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.8" data-path="generator.html">
            
                <a href="generator.html">
            
                    
                    generator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8.9" data-path="async.html">
            
                <a href="async.html">
            
                    
                    async
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="标准对象.html">
            
                <a href="标准对象.html">
            
                    
                    标准对象
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.9.1" data-path="SetMap.html">
            
                <a href="SetMap.html">
            
                    
                    Set,Map
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.2" data-path="Date.html">
            
                <a href="Date.html">
            
                    
                    Date
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.3" data-path="Math.html">
            
                <a href="Math.html">
            
                    
                    Math
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.4" data-path="Proxy.html">
            
                <a href="Proxy.html">
            
                    
                    Proxy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.5" data-path="RepExp.html">
            
                <a href="RepExp.html">
            
                    
                    正则表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.6" data-path="正则表达式.html">
            
                <a href="正则表达式.html">
            
                    
                    正则表达式别篇
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9.7" data-path="json.html">
            
                <a href="json.html">
            
                    
                    JSON
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="面向对象编程.html">
            
                <a href="面向对象编程.html">
            
                    
                    面向对象编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.10.1" data-path="对象的扩展.html">
            
                <a href="对象的扩展.html">
            
                    
                    对象的扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.2" data-path="创建对象.html">
            
                <a href="创建对象.html">
            
                    
                    创建对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.3" data-path="原型继承.html">
            
                <a href="原型继承.html">
            
                    
                    原型继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.4" data-path="class继承.html">
            
                <a href="class继承.html">
            
                    
                    class继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10.5" data-path="模块化Module.html">
            
                <a href="模块化Module.html">
            
                    
                    模块化Module
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="异常处理.html">
            
                <a href="异常处理.html">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="编程风格.html">
            
                <a href="编程风格.html">
            
                    
                    编程风格
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../js扩展/js扩展.html">
            
                <a href="../js扩展/js扩展.html">
            
                    
                    js 扩展
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../js扩展/字符串.html">
            
                <a href="../js扩展/字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../浏览器/浏览器.html">
            
                <a href="../浏览器/浏览器.html">
            
                    
                    浏览器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../浏览器/浏览器对象.html">
            
                <a href="../浏览器/浏览器对象.html">
            
                    
                    浏览器对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../浏览器/操作DOM.html">
            
                <a href="../浏览器/操作DOM.html">
            
                    
                    操作DOM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../浏览器/更新DOM.html">
            
                <a href="../浏览器/更新DOM.html">
            
                    
                    更新DOM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="../浏览器/插入DOM.html">
            
                <a href="../浏览器/插入DOM.html">
            
                    
                    插入DOM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.3" data-path="../浏览器/删除DOM.html">
            
                <a href="../浏览器/删除DOM.html">
            
                    
                    删除DOM
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../浏览器/DOM事件.html">
            
                <a href="../浏览器/DOM事件.html">
            
                    
                    DOM事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../浏览器/操作表单.html">
            
                <a href="../浏览器/操作表单.html">
            
                    
                    操作表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../浏览器/操作文件.html">
            
                <a href="../浏览器/操作文件.html">
            
                    
                    操作文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../浏览器/AJAX.html">
            
                <a href="../浏览器/AJAX.html">
            
                    
                    AJAX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../浏览器/Canvas.html">
            
                <a href="../浏览器/Canvas.html">
            
                    
                    Canvas
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../Jquery/jquery.html">
            
                <a href="../Jquery/jquery.html">
            
                    
                    Jquery
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Jquery/选择器.html">
            
                <a href="../Jquery/选择器.html">
            
                    
                    选择器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1.1" data-path="../Jquery/层级选择器.html">
            
                <a href="../Jquery/层级选择器.html">
            
                    
                    层级选择器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.2" data-path="../Jquery/查找和过滤.html">
            
                <a href="../Jquery/查找和过滤.html">
            
                    
                    查找和过滤
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Jquery/操作DOM.html">
            
                <a href="../Jquery/操作DOM.html">
            
                    
                    操作DOM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.2.1" data-path="../Jquery/修改DOM结构.html">
            
                <a href="../Jquery/修改DOM结构.html">
            
                    
                    修改DOM结构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Jquery/事件.html">
            
                <a href="../Jquery/事件.html">
            
                    
                    事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Jquery/动画.html">
            
                <a href="../Jquery/动画.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Jquery/AJAX.html">
            
                <a href="../Jquery/AJAX.html">
            
                    
                    AJAX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../Jquery/扩展.html">
            
                <a href="../Jquery/扩展.html">
            
                    
                    扩展
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../nodejs/nodejs.html">
            
                <a href="../nodejs/nodejs.html">
            
                    
                    Nodejs
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../nodejs/模块.html">
            
                <a href="../nodejs/模块.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../nodejs/path.html">
            
                <a href="../nodejs/path.html">
            
                    
                    path
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../nodejs/文件操作.html">
            
                <a href="../nodejs/文件操作.html">
            
                    
                    文件操作 fs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../nodejs/流Stream.html">
            
                <a href="../nodejs/流Stream.html">
            
                    
                    流Stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../nodejs/zlib压缩解压缩.html">
            
                <a href="../nodejs/zlib压缩解压缩.html">
            
                    
                    zlib压缩解压缩
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../nodejs/net网络.html">
            
                <a href="../nodejs/net网络.html">
            
                    
                    net网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../nodejs/http.html">
            
                <a href="../nodejs/http.html">
            
                    
                    http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../nodejs/express框架.html">
            
                <a href="../nodejs/express框架.html">
            
                    
                    express框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../nodejs/process进程.html">
            
                <a href="../nodejs/process进程.html">
            
                    
                    process 进程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../nodejs/child_process.html">
            
                <a href="../nodejs/child_process.html">
            
                    
                    child_process
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../nodejs/os.html">
            
                <a href="../nodejs/os.html">
            
                    
                    os-操作系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../react/react.html">
            
                <a href="../react/react.html">
            
                    
                    React
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >变量作用域与解构赋值</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x53D8;&#x91CF;&#x4F5C;&#x7528;&#x57DF;&#x4E0E;&#x89E3;&#x6784;&#x8D4B;&#x503C;">&#x53D8;&#x91CF;&#x4F5C;&#x7528;&#x57DF;&#x4E0E;&#x89E3;&#x6784;&#x8D4B;&#x503C;</h1>
<h3 id="&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;">&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;</h3>
<p>&#x7531;&#x4E8E;JavaScript&#x7684;&#x53D8;&#x91CF;&#x4F5C;&#x7528;&#x57DF;&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x51FD;&#x6570;&#x5185;&#x90E8;&#xFF0C;&#x6211;&#x4EEC;&#x5728;<code>for</code>&#x5FAA;&#x73AF;&#x7B49;&#x8BED;&#x53E5;&#x5757;&#x4E2D;&#x662F;&#x65E0;&#x6CD5;&#x5B9A;&#x4E49;&#x5177;&#x6709;&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x53D8;&#x91CF;&#x7684;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-meta">&apos;use strict&apos;</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-number">100</span>; i++) {
        <span class="hljs-comment">//</span>
    }
    i += <span class="hljs-number">100</span>; <span class="hljs-comment">// &#x4ECD;&#x7136;&#x53EF;&#x4EE5;&#x5F15;&#x7528;&#x53D8;&#x91CF;i</span>
}
</code></pre>
<p>&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;ES6&#x5F15;&#x5165;&#x4E86;&#x65B0;&#x7684;&#x5173;&#x952E;&#x5B57;<code>let</code>&#xFF0C;&#x7528;<code>let</code>&#x66FF;&#x4EE3;<code>var</code>&#x53EF;&#x4EE5;&#x7533;&#x660E;&#x4E00;&#x4E2A;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x53D8;&#x91CF;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-meta">&apos;use strict&apos;</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> sum = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-number">100</span>; i++) {
        sum += i;
    }
    <span class="hljs-comment">// SyntaxError:</span>
    i += <span class="hljs-number">1</span>;
}
</code></pre>
<h3 id="&#x5E38;&#x91CF;">&#x5E38;&#x91CF;</h3>
<p>&#x7531;&#x4E8E;<code>var</code>&#x548C;<code>let</code>&#x7533;&#x660E;&#x7684;&#x662F;&#x53D8;&#x91CF;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x7533;&#x660E;&#x4E00;&#x4E2A;&#x5E38;&#x91CF;&#xFF0C;&#x5728;ES6&#x4E4B;&#x524D;&#x662F;&#x4E0D;&#x884C;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x901A;&#x5E38;&#x7528;&#x5168;&#x90E8;&#x5927;&#x5199;&#x7684;&#x53D8;&#x91CF;&#x6765;&#x8868;&#x793A;&#x201C;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x5E38;&#x91CF;&#xFF0C;&#x4E0D;&#x8981;&#x4FEE;&#x6539;&#x5B83;&#x7684;&#x503C;&#x201D;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> PI = <span class="hljs-number">3.14</span>;
</code></pre>
<p>ES6&#x6807;&#x51C6;&#x5F15;&#x5165;&#x4E86;&#x65B0;&#x7684;&#x5173;&#x952E;&#x5B57;<code>const</code>&#x6765;&#x5B9A;&#x4E49;&#x5E38;&#x91CF;&#xFF0C;<code>const</code>&#x4E0E;<code>let</code>&#x90FD;&#x5177;&#x6709;&#x5757;&#x7EA7;&#x4F5C;&#x7528;&#x57DF;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-meta">&apos;use strict&apos;</span>;

<span class="hljs-keyword">const</span> PI = <span class="hljs-number">3.14</span>;
PI = <span class="hljs-number">3</span>; <span class="hljs-comment">// &#x67D0;&#x4E9B;&#x6D4F;&#x89C8;&#x5668;&#x4E0D;&#x62A5;&#x9519;&#xFF0C;&#x4F46;&#x662F;&#x65E0;&#x6548;&#x679C;&#xFF01;</span>
PI; <span class="hljs-comment">// 3.14</span>
</code></pre>
<h3 id="&#x89E3;&#x6784;&#x8D4B;&#x503C;">&#x89E3;&#x6784;&#x8D4B;&#x503C;</h3>
<p>&#x4ECE;ES6&#x5F00;&#x59CB;&#xFF0C;JavaScript&#x5F15;&#x5165;&#x4E86;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x540C;&#x65F6;&#x5BF9;&#x4E00;&#x7EC4;&#x53D8;&#x91CF;&#x8FDB;&#x884C;&#x8D4B;&#x503C;&#x3002;</p>
<p>&#x4EC0;&#x4E48;&#x662F;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#xFF1F;&#x6211;&#x4EEC;&#x5148;&#x770B;&#x770B;&#x4F20;&#x7EDF;&#x7684;&#x505A;&#x6CD5;&#xFF0C;&#x5982;&#x4F55;&#x628A;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x5143;&#x7D20;&#x5206;&#x522B;&#x8D4B;&#x503C;&#x7ED9;&#x51E0;&#x4E2A;&#x53D8;&#x91CF;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> array = [<span class="hljs-string">&apos;hello&apos;</span>, <span class="hljs-string">&apos;JavaScript&apos;</span>, <span class="hljs-string">&apos;ES6&apos;</span>];
<span class="hljs-keyword">var</span> x = array[<span class="hljs-number">0</span>];
<span class="hljs-keyword">var</span> y = array[<span class="hljs-number">1</span>];
<span class="hljs-keyword">var</span> z = array[<span class="hljs-number">2</span>];
</code></pre>
<p>&#x73B0;&#x5728;&#xFF0C;&#x5728;ES6&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#xFF0C;&#x76F4;&#x63A5;&#x5BF9;&#x591A;&#x4E2A;&#x53D8;&#x91CF;&#x540C;&#x65F6;&#x8D4B;&#x503C;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x5982;&#x679C;&#x6D4F;&#x89C8;&#x5668;&#x652F;&#x6301;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x5C31;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;: </span>
<span class="hljs-keyword">var</span> [x, y, z] = [<span class="hljs-string">&apos;hello&apos;</span>, <span class="hljs-string">&apos;JavaScript&apos;</span>, <span class="hljs-string">&apos;ES6&apos;</span>];
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x5BF9;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x8FDB;&#x884C;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x65F6;&#xFF0C;&#x591A;&#x4E2A;&#x53D8;&#x91CF;&#x8981;&#x7528;<code>[...]</code>&#x62EC;&#x8D77;&#x6765;&#x3002;</p>
<p>&#x5982;&#x679C;&#x6570;&#x7EC4;&#x672C;&#x8EAB;&#x8FD8;&#x6709;&#x5D4C;&#x5957;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E0B;&#x9762;&#x7684;&#x5F62;&#x5F0F;&#x8FDB;&#x884C;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#xFF0C;&#x6CE8;&#x610F;&#x5D4C;&#x5957;&#x5C42;&#x6B21;&#x548C;&#x4F4D;&#x7F6E;&#x8981;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> [x, [y, z]] = [<span class="hljs-string">&apos;hello&apos;</span>, [<span class="hljs-string">&apos;JavaScript&apos;</span>, <span class="hljs-string">&apos;ES6&apos;</span>]];
x; <span class="hljs-comment">// &apos;hello&apos;</span>
y; <span class="hljs-comment">// &apos;JavaScript&apos;</span>
z; <span class="hljs-comment">// &apos;ES6&apos;</span>
</code></pre>
<p>&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x8FD8;&#x53EF;&#x4EE5;&#x5FFD;&#x7565;&#x67D0;&#x4E9B;&#x5143;&#x7D20;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> [, , z] = [<span class="hljs-string">&apos;hello&apos;</span>, <span class="hljs-string">&apos;JavaScript&apos;</span>, <span class="hljs-string">&apos;ES6&apos;</span>]; <span class="hljs-comment">// &#x5FFD;&#x7565;&#x524D;&#x4E24;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x53EA;&#x5BF9;z&#x8D4B;&#x503C;&#x7B2C;&#x4E09;&#x4E2A;&#x5143;&#x7D20;</span>
z; <span class="hljs-comment">// &apos;ES6&apos;</span>
</code></pre>
<h3 id="&#x9ED8;&#x8BA4;&#x503C;">&#x9ED8;&#x8BA4;&#x503C;</h3>
<p>&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x5141;&#x8BB8;&#x6307;&#x5B9A;&#x9ED8;&#x8BA4;&#x503C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> [foo = <span class="hljs-literal">true</span>] = [];
foo <span class="hljs-comment">// true</span>

<span class="hljs-keyword">let</span> [x, y = <span class="hljs-string">&apos;b&apos;</span>] = [<span class="hljs-string">&apos;a&apos;</span>]; <span class="hljs-comment">// x=&apos;a&apos;, y=&apos;b&apos;</span>
<span class="hljs-keyword">let</span> [x, y = <span class="hljs-string">&apos;b&apos;</span>] = [<span class="hljs-string">&apos;a&apos;</span>, <span class="hljs-literal">undefined</span>]; <span class="hljs-comment">// x=&apos;a&apos;, y=&apos;b&apos;</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;ES6 &#x5185;&#x90E8;&#x4F7F;&#x7528;&#x4E25;&#x683C;&#x76F8;&#x7B49;&#x8FD0;&#x7B97;&#x7B26;&#xFF08;<code>===</code>&#xFF09;&#xFF0C;&#x5224;&#x65AD;&#x4E00;&#x4E2A;&#x4F4D;&#x7F6E;&#x662F;&#x5426;&#x6709;&#x503C;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x53EA;&#x6709;&#x5F53;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x6210;&#x5458;&#x4E25;&#x683C;&#x7B49;&#x4E8E;<code>undefined</code>&#xFF0C;&#x9ED8;&#x8BA4;&#x503C;&#x624D;&#x4F1A;&#x751F;&#x6548;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> [x = <span class="hljs-number">1</span>] = [<span class="hljs-literal">undefined</span>];
x <span class="hljs-comment">// 1</span>

<span class="hljs-keyword">let</span> [x = <span class="hljs-number">1</span>] = [<span class="hljs-literal">null</span>];
x <span class="hljs-comment">// null</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x6210;&#x5458;&#x662F;<code>null</code>&#xFF0C;&#x9ED8;&#x8BA4;&#x503C;&#x5C31;&#x4E0D;&#x4F1A;&#x751F;&#x6548;&#xFF0C;&#x56E0;&#x4E3A;<code>null</code>&#x4E0D;&#x4E25;&#x683C;&#x7B49;&#x4E8E;<code>undefined</code>&#x3002;</p>
<p>&#x9ED8;&#x8BA4;&#x503C;&#x53EF;&#x4EE5;&#x5F15;&#x7528;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x7684;&#x5176;&#x4ED6;&#x53D8;&#x91CF;&#xFF0C;&#x4F46;&#x8BE5;&#x53D8;&#x91CF;&#x5FC5;&#x987B;&#x5DF2;&#x7ECF;&#x58F0;&#x660E;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> [x = <span class="hljs-number">1</span>, y = x] = [];     <span class="hljs-comment">// x=1; y=1</span>
<span class="hljs-keyword">let</span> [x = <span class="hljs-number">1</span>, y = x] = [<span class="hljs-number">2</span>];    <span class="hljs-comment">// x=2; y=2</span>
<span class="hljs-keyword">let</span> [x = <span class="hljs-number">1</span>, y = x] = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>]; <span class="hljs-comment">// x=1; y=2</span>
<span class="hljs-keyword">let</span> [x = y, y = <span class="hljs-number">1</span>] = [];     <span class="hljs-comment">// ReferenceError: y is not defined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#x4E4B;&#x6240;&#x4EE5;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x662F;&#x56E0;&#x4E3A;<code>x</code>&#x7528;<code>y</code>&#x505A;&#x9ED8;&#x8BA4;&#x503C;&#x65F6;&#xFF0C;<code>y</code>&#x8FD8;&#x6CA1;&#x6709;&#x58F0;&#x660E;&#x3002;</p>
<h3 id="&#x5BF9;&#x8C61;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;">&#x5BF9;&#x8C61;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;</h3>
<p>&#x5BF9;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x8FDB;&#x884C;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x65F6;&#xFF0C;&#x540C;&#x6837;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x5BF9;&#x5D4C;&#x5957;&#x7684;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x8D4B;&#x503C;&#xFF0C;&#x53EA;&#x8981;&#x4FDD;&#x8BC1;&#x5BF9;&#x5E94;&#x7684;&#x5C42;&#x6B21;&#x662F;&#x4E00;&#x81F4;&#x7684;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> person = {
    name: <span class="hljs-string">&apos;&#x5C0F;&#x660E;&apos;</span>,
    age: <span class="hljs-number">20</span>,
    gender: <span class="hljs-string">&apos;male&apos;</span>,
    passport: <span class="hljs-string">&apos;G-12345678&apos;</span>,
    school: <span class="hljs-string">&apos;No.4 middle school&apos;</span>,
    address: {
        city: <span class="hljs-string">&apos;Beijing&apos;</span>,
        street: <span class="hljs-string">&apos;No.1 Road&apos;</span>,
        zipcode: <span class="hljs-string">&apos;100001&apos;</span>
    }
};
<span class="hljs-keyword">var</span> {name, address: {city, zip}} = person;
name; <span class="hljs-comment">// &apos;&#x5C0F;&#x660E;&apos;</span>
city; <span class="hljs-comment">// &apos;Beijing&apos;</span>
zip; <span class="hljs-comment">// undefined, &#x56E0;&#x4E3A;&#x5C5E;&#x6027;&#x540D;&#x662F;zipcode&#x800C;&#x4E0D;&#x662F;zip</span>
<span class="hljs-comment">// &#x6CE8;&#x610F;: address&#x4E0D;&#x662F;&#x53D8;&#x91CF;&#xFF0C;&#x800C;&#x662F;&#x4E3A;&#x4E86;&#x8BA9;city&#x548C;zip&#x83B7;&#x5F97;&#x5D4C;&#x5957;&#x7684;address&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;:</span>
address; <span class="hljs-comment">// Uncaught ReferenceError: address is not defined</span>
</code></pre>
<p>&#x4F7F;&#x7528;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x5BF9;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x8D4B;&#x503C;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x5BF9;&#x5E94;&#x7684;&#x5C5E;&#x6027;&#x4E0D;&#x5B58;&#x5728;&#xFF0C;&#x53D8;&#x91CF;&#x5C06;&#x88AB;&#x8D4B;&#x503C;&#x4E3A;<code>undefined</code>&#xFF0C;&#x8FD9;&#x548C;&#x5F15;&#x7528;&#x4E00;&#x4E2A;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x5C5E;&#x6027;&#x83B7;&#x5F97;<code>undefined</code>&#x662F;&#x4E00;&#x81F4;&#x7684;&#x3002;&#x5982;&#x679C;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x548C;&#x5C5E;&#x6027;&#x540D;&#x4E0D;&#x4E00;&#x81F4;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x8BED;&#x6CD5;&#x83B7;&#x53D6;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> person = {
    name: <span class="hljs-string">&apos;&#x5C0F;&#x660E;&apos;</span>,
    age: <span class="hljs-number">20</span>,
    gender: <span class="hljs-string">&apos;male&apos;</span>,
    passport: <span class="hljs-string">&apos;G-12345678&apos;</span>,
    school: <span class="hljs-string">&apos;No.4 middle school&apos;</span>
};

<span class="hljs-comment">// &#x628A;passport&#x5C5E;&#x6027;&#x8D4B;&#x503C;&#x7ED9;&#x53D8;&#x91CF;id:</span>
<span class="hljs-keyword">let</span> {name, passport:id} = person;
name; <span class="hljs-comment">// &apos;&#x5C0F;&#x660E;&apos;</span>
id; <span class="hljs-comment">// &apos;G-12345678&apos;</span>
<span class="hljs-comment">// &#x6CE8;&#x610F;: passport&#x4E0D;&#x662F;&#x53D8;&#x91CF;&#xFF0C;&#x800C;&#x662F;&#x4E3A;&#x4E86;&#x8BA9;&#x53D8;&#x91CF;id&#x83B7;&#x5F97;passport&#x5C5E;&#x6027;:</span>
passport; <span class="hljs-comment">// Uncaught ReferenceError: passport is not defined</span>
</code></pre>
<p>&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x8FD8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x907F;&#x514D;&#x4E86;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x5C5E;&#x6027;&#x8FD4;&#x56DE;<code>undefined</code>&#x7684;&#x95EE;&#x9898;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> person = {
    name: <span class="hljs-string">&apos;&#x5C0F;&#x660E;&apos;</span>,
    age: <span class="hljs-number">20</span>,
    gender: <span class="hljs-string">&apos;male&apos;</span>,
    passport: <span class="hljs-string">&apos;G-12345678&apos;</span>
};

<span class="hljs-comment">// &#x5982;&#x679C;person&#x5BF9;&#x8C61;&#x6CA1;&#x6709;single&#x5C5E;&#x6027;&#xFF0C;&#x9ED8;&#x8BA4;&#x8D4B;&#x503C;&#x4E3A;true:</span>
<span class="hljs-keyword">var</span> {name, single=<span class="hljs-literal">true</span>} = person;
name; <span class="hljs-comment">// &apos;&#x5C0F;&#x660E;&apos;</span>
single; <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x6709;&#x4E9B;&#x65F6;&#x5019;&#xFF0C;&#x5982;&#x679C;&#x53D8;&#x91CF;&#x5DF2;&#x7ECF;&#x88AB;&#x58F0;&#x660E;&#x4E86;&#xFF0C;&#x518D;&#x6B21;&#x8D4B;&#x503C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6B63;&#x786E;&#x7684;&#x5199;&#x6CD5;&#x4E5F;&#x4F1A;&#x62A5;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x58F0;&#x660E;&#x53D8;&#x91CF;:</span>
<span class="hljs-keyword">var</span> x, y;
<span class="hljs-comment">// &#x89E3;&#x6784;&#x8D4B;&#x503C;:</span>
{x, y} = { name: <span class="hljs-string">&apos;&#x5C0F;&#x660E;&apos;</span>, x: <span class="hljs-number">100</span>, y: <span class="hljs-number">200</span>};
<span class="hljs-comment">// &#x8BED;&#x6CD5;&#x9519;&#x8BEF;: Uncaught SyntaxError: Unexpected token =</span>
</code></pre>
<p>&#x8FD9;&#x662F;&#x56E0;&#x4E3A;JavaScript&#x5F15;&#x64CE;&#x628A;<code>{</code>&#x5F00;&#x5934;&#x7684;&#x8BED;&#x53E5;&#x5F53;&#x4F5C;&#x4E86;&#x5757;&#x5904;&#x7406;&#xFF0C;&#x4E8E;&#x662F;<code>=</code>&#x4E0D;&#x518D;&#x5408;&#x6CD5;&#x3002;&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#x662F;&#x7528;&#x5C0F;&#x62EC;&#x53F7;&#x62EC;&#x8D77;&#x6765;&#xFF1A;</p>
<pre><code class="lang-javascript">({x, y} = { name: <span class="hljs-string">&apos;&#x5C0F;&#x660E;&apos;</span>, x: <span class="hljs-number">100</span>, y: <span class="hljs-number">200</span>});
</code></pre>
<p>&#x5BF9;&#x8C61;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x5F88;&#x65B9;&#x4FBF;&#x5730;&#x5C06;&#x73B0;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x8D4B;&#x503C;&#x5230;&#x67D0;&#x4E2A;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x4F8B;&#x4E00;</span>
<span class="hljs-keyword">let</span> { log, sin, cos } = <span class="hljs-built_in">Math</span>;

<span class="hljs-comment">// &#x4F8B;&#x4E8C;</span>
<span class="hljs-keyword">const</span> { log } = <span class="hljs-built_in">console</span>;
log(<span class="hljs-string">&apos;hello&apos;</span>) <span class="hljs-comment">// hello</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;&#x4F8B;&#x4E00;&#x5C06;<code>Math</code>&#x5BF9;&#x8C61;&#x7684;&#x5BF9;&#x6570;&#x3001;&#x6B63;&#x5F26;&#x3001;&#x4F59;&#x5F26;&#x4E09;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x8D4B;&#x503C;&#x5230;&#x5BF9;&#x5E94;&#x7684;&#x53D8;&#x91CF;&#x4E0A;&#xFF0C;&#x4F7F;&#x7528;&#x8D77;&#x6765;&#x5C31;&#x4F1A;&#x65B9;&#x4FBF;&#x5F88;&#x591A;&#x3002;&#x4F8B;&#x4E8C;&#x5C06;<code>console.log</code>&#x8D4B;&#x503C;&#x5230;<code>log</code>&#x53D8;&#x91CF;&#x3002;</p>
<p>&#x5982;&#x679C;&#x53D8;&#x91CF;&#x540D;&#x4E0E;&#x5C5E;&#x6027;&#x540D;&#x4E0D;&#x4E00;&#x81F4;&#xFF0C;&#x5FC5;&#x987B;&#x5199;&#x6210;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> { foo: baz } = { foo: <span class="hljs-string">&apos;aaa&apos;</span>, bar: <span class="hljs-string">&apos;bbb&apos;</span> };
baz <span class="hljs-comment">// &quot;aaa&quot;</span>

<span class="hljs-keyword">let</span> obj = { first: <span class="hljs-string">&apos;hello&apos;</span>, last: <span class="hljs-string">&apos;world&apos;</span> };
<span class="hljs-keyword">let</span> { first: f, last: l } = obj;
f <span class="hljs-comment">// &apos;hello&apos;</span>
l <span class="hljs-comment">// &apos;world&apos;</span>
</code></pre>
<p>&#x8FD9;&#x5B9E;&#x9645;&#x4E0A;&#x8BF4;&#x660E;&#xFF0C;&#x5BF9;&#x8C61;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x662F;&#x4E0B;&#x9762;&#x5F62;&#x5F0F;&#x7684;&#x7B80;&#x5199;&#xFF08;&#x53C2;&#x89C1;&#x300A;&#x5BF9;&#x8C61;&#x7684;&#x6269;&#x5C55;&#x300B;&#x4E00;&#x7AE0;&#xFF09;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> { foo: foo, bar: bar } = { foo: <span class="hljs-string">&apos;aaa&apos;</span>, bar: <span class="hljs-string">&apos;bbb&apos;</span> };
</code></pre>
<p>&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x5BF9;&#x8C61;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x7684;&#x5185;&#x90E8;&#x673A;&#x5236;&#xFF0C;&#x662F;&#x5148;&#x627E;&#x5230;&#x540C;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8D4B;&#x7ED9;&#x5BF9;&#x5E94;&#x7684;&#x53D8;&#x91CF;&#x3002;&#x771F;&#x6B63;&#x88AB;&#x8D4B;&#x503C;&#x7684;&#x662F;&#x540E;&#x8005;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x524D;&#x8005;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> { foo: baz } = { foo: <span class="hljs-string">&apos;aaa&apos;</span>, bar: <span class="hljs-string">&apos;bbb&apos;</span> };
baz <span class="hljs-comment">// &quot;aaa&quot;</span>
foo <span class="hljs-comment">// error: foo is not defined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;<code>foo</code>&#x662F;&#x5339;&#x914D;&#x7684;&#x6A21;&#x5F0F;&#xFF0C;<code>baz</code>&#x624D;&#x662F;&#x53D8;&#x91CF;&#x3002;&#x771F;&#x6B63;&#x88AB;&#x8D4B;&#x503C;&#x7684;&#x662F;&#x53D8;&#x91CF;<code>baz</code>&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x6A21;&#x5F0F;<code>foo</code>&#x3002;</p>
<p>&#x4E0E;&#x6570;&#x7EC4;&#x4E00;&#x6837;&#xFF0C;&#x89E3;&#x6784;&#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x5D4C;&#x5957;&#x7ED3;&#x6784;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> obj = {
  p: [
    <span class="hljs-string">&apos;Hello&apos;</span>,
    { y: <span class="hljs-string">&apos;World&apos;</span> }
  ]
};

<span class="hljs-keyword">let</span> { p: [x, { y }] } = obj;
x <span class="hljs-comment">// &quot;Hello&quot;</span>
y <span class="hljs-comment">// &quot;World&quot;</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x8FD9;&#x65F6;<code>p</code>&#x662F;&#x6A21;&#x5F0F;&#xFF0C;&#x4E0D;&#x662F;&#x53D8;&#x91CF;&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x4F1A;&#x88AB;&#x8D4B;&#x503C;&#x3002;&#x5982;&#x679C;<code>p</code>&#x4E5F;&#x8981;&#x4F5C;&#x4E3A;&#x53D8;&#x91CF;&#x8D4B;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x5199;&#x6210;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> obj = {
  p: [
    <span class="hljs-string">&apos;Hello&apos;</span>,
    { y: <span class="hljs-string">&apos;World&apos;</span> }
  ]
};

<span class="hljs-keyword">let</span> { p, p: [x, { y }] } = obj;
x <span class="hljs-comment">// &quot;Hello&quot;</span>
y <span class="hljs-comment">// &quot;World&quot;</span>
p <span class="hljs-comment">// [&quot;Hello&quot;, {y: &quot;World&quot;}]</span>
</code></pre>
<h3 id="&#x6CE8;&#x610F;&#x70B9;"><font color="red">&#x6CE8;&#x610F;&#x70B9;</font></h3>
<p>&#xFF08;1&#xFF09;&#x5982;&#x679C;&#x8981;&#x5C06;&#x4E00;&#x4E2A;&#x5DF2;&#x7ECF;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x91CF;&#x7528;&#x4E8E;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#xFF0C;&#x5FC5;&#x987B;&#x975E;&#x5E38;&#x5C0F;&#x5FC3;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x9519;&#x8BEF;&#x7684;&#x5199;&#x6CD5;</span>
<span class="hljs-keyword">let</span> x;
{x} = {x: <span class="hljs-number">1</span>};
<span class="hljs-comment">// SyntaxError: syntax error</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;&#x5199;&#x6CD5;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x56E0;&#x4E3A; JavaScript &#x5F15;&#x64CE;&#x4F1A;&#x5C06;<code>{x}</code>&#x7406;&#x89E3;&#x6210;&#x4E00;&#x4E2A;&#x4EE3;&#x7801;&#x5757;&#xFF0C;&#x4ECE;&#x800C;&#x53D1;&#x751F;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#x3002;&#x53EA;&#x6709;&#x4E0D;&#x5C06;&#x5927;&#x62EC;&#x53F7;&#x5199;&#x5728;&#x884C;&#x9996;&#xFF0C;&#x907F;&#x514D; JavaScript &#x5C06;&#x5176;&#x89E3;&#x91CA;&#x4E3A;&#x4EE3;&#x7801;&#x5757;&#xFF0C;&#x624D;&#x80FD;&#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x6B63;&#x786E;&#x7684;&#x5199;&#x6CD5;</span>
<span class="hljs-keyword">let</span> x;
({x} = {x: <span class="hljs-number">1</span>});
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5C06;&#x6574;&#x4E2A;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#xFF0C;&#x653E;&#x5728;&#x4E00;&#x4E2A;&#x5706;&#x62EC;&#x53F7;&#x91CC;&#x9762;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x6B63;&#x786E;&#x6267;&#x884C;&#x3002;&#x5173;&#x4E8E;&#x5706;&#x62EC;&#x53F7;&#x4E0E;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x7684;&#x5173;&#x7CFB;&#xFF0C;&#x53C2;&#x89C1;&#x4E0B;&#x6587;&#x3002;</p>
<p>2&#xFF09;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x5141;&#x8BB8;&#x7B49;&#x53F7;&#x5DE6;&#x8FB9;&#x7684;&#x6A21;&#x5F0F;&#x4E4B;&#x4E2D;&#xFF0C;&#x4E0D;&#x653E;&#x7F6E;&#x4EFB;&#x4F55;&#x53D8;&#x91CF;&#x540D;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x53EF;&#x4EE5;&#x5199;&#x51FA;&#x975E;&#x5E38;&#x53E4;&#x602A;&#x7684;&#x8D4B;&#x503C;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<pre><code class="lang-javascript">({} = [<span class="hljs-literal">true</span>, <span class="hljs-literal">false</span>]);
({} = <span class="hljs-string">&apos;abc&apos;</span>);
({} = []);
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x867D;&#x7136;&#x6BEB;&#x65E0;&#x610F;&#x4E49;&#xFF0C;&#x4F46;&#x662F;&#x8BED;&#x6CD5;&#x662F;&#x5408;&#x6CD5;&#x7684;&#xFF0C;&#x53EF;&#x4EE5;&#x6267;&#x884C;&#x3002;</p>
<p>&#xFF08;3&#xFF09;&#x7531;&#x4E8E;&#x6570;&#x7EC4;&#x672C;&#x8D28;&#x662F;&#x7279;&#x6B8A;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x5BF9;&#x6570;&#x7EC4;&#x8FDB;&#x884C;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x89E3;&#x6784;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> arr = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-keyword">let</span> {<span class="hljs-number">0</span> : first, [arr.length - <span class="hljs-number">1</span>] : last} = arr;
first <span class="hljs-comment">// 1</span>
last <span class="hljs-comment">// 3</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5BF9;&#x6570;&#x7EC4;&#x8FDB;&#x884C;&#x5BF9;&#x8C61;&#x89E3;&#x6784;&#x3002;&#x6570;&#x7EC4;<code>arr</code>&#x7684;<code>0</code>&#x952E;&#x5BF9;&#x5E94;&#x7684;&#x503C;&#x662F;<code>1</code>&#xFF0C;<code>[arr.length - 1]</code>&#x5C31;&#x662F;<code>2</code>&#x952E;&#xFF0C;&#x5BF9;&#x5E94;&#x7684;&#x503C;&#x662F;<code>3</code>&#x3002;&#x65B9;&#x62EC;&#x53F7;&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#xFF0C;&#x5C5E;&#x4E8E;&#x201C;&#x5C5E;&#x6027;&#x540D;&#x8868;&#x8FBE;&#x5F0F;&#x201D;&#xFF08;&#x53C2;&#x89C1;&#x300A;&#x5BF9;&#x8C61;&#x7684;&#x6269;&#x5C55;&#x300B;&#x4E00;&#x7AE0;&#xFF09;&#x3002;</p>
<h3 id="&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;">&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;</h3>
<p>&#x5B57;&#x7B26;&#x4E32;&#x4E5F;&#x53EF;&#x4EE5;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x3002;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x6B64;&#x65F6;&#xFF0C;&#x5B57;&#x7B26;&#x4E32;&#x88AB;&#x8F6C;&#x6362;&#x6210;&#x4E86;&#x4E00;&#x4E2A;&#x7C7B;&#x4F3C;&#x6570;&#x7EC4;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> [a, b, c, d, e] = <span class="hljs-string">&apos;hello&apos;</span>;
a <span class="hljs-comment">// &quot;h&quot;</span>
b <span class="hljs-comment">// &quot;e&quot;</span>
c <span class="hljs-comment">// &quot;l&quot;</span>
d <span class="hljs-comment">// &quot;l&quot;</span>
e <span class="hljs-comment">// &quot;o&quot;</span>
</code></pre>
<p>&#x7C7B;&#x4F3C;&#x6570;&#x7EC4;&#x7684;&#x5BF9;&#x8C61;&#x90FD;&#x6709;&#x4E00;&#x4E2A;<code>length</code>&#x5C5E;&#x6027;&#xFF0C;&#x56E0;&#x6B64;&#x8FD8;&#x53EF;&#x4EE5;&#x5BF9;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> {length : len} = <span class="hljs-string">&apos;hello&apos;</span>;
len <span class="hljs-comment">// 5</span>
</code></pre>
<h3 id="&#x6570;&#x503C;&#x548C;&#x5E03;&#x5C14;&#x503C;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;">&#x6570;&#x503C;&#x548C;&#x5E03;&#x5C14;&#x503C;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;</h3>
<p>&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x7B49;&#x53F7;&#x53F3;&#x8FB9;&#x662F;&#x6570;&#x503C;&#x548C;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x5219;&#x4F1A;&#x5148;&#x8F6C;&#x4E3A;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> {toString: s} = <span class="hljs-number">123</span>;
s === <span class="hljs-built_in">Number</span>.prototype.toString <span class="hljs-comment">// true</span>

<span class="hljs-keyword">let</span> {toString: s} = <span class="hljs-literal">true</span>;
s === <span class="hljs-built_in">Boolean</span>.prototype.toString <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x6570;&#x503C;&#x548C;&#x5E03;&#x5C14;&#x503C;&#x7684;&#x5305;&#x88C5;&#x5BF9;&#x8C61;&#x90FD;&#x6709;<code>toString</code>&#x5C5E;&#x6027;&#xFF0C;&#x56E0;&#x6B64;&#x53D8;&#x91CF;<code>s</code>&#x90FD;&#x80FD;&#x53D6;&#x5230;&#x503C;&#x3002;</p>
<p>&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x7684;&#x89C4;&#x5219;&#x662F;&#xFF0C;&#x53EA;&#x8981;&#x7B49;&#x53F7;&#x53F3;&#x8FB9;&#x7684;&#x503C;&#x4E0D;&#x662F;&#x5BF9;&#x8C61;&#x6216;&#x6570;&#x7EC4;&#xFF0C;&#x5C31;&#x5148;&#x5C06;&#x5176;&#x8F6C;&#x4E3A;&#x5BF9;&#x8C61;&#x3002;&#x7531;&#x4E8E;<code>undefined</code>&#x548C;<code>null</code>&#x65E0;&#x6CD5;&#x8F6C;&#x4E3A;&#x5BF9;&#x8C61;&#xFF0C;&#x6240;&#x4EE5;&#x5BF9;&#x5B83;&#x4EEC;&#x8FDB;&#x884C;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#xFF0C;&#x90FD;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> { prop: x } = <span class="hljs-literal">undefined</span>; <span class="hljs-comment">// TypeError</span>
<span class="hljs-keyword">let</span> { prop: y } = <span class="hljs-literal">null</span>; <span class="hljs-comment">// TypeError</span>
</code></pre>
<h3 id="&#x51FD;&#x6570;&#x53C2;&#x6570;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;">&#x51FD;&#x6570;&#x53C2;&#x6570;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;</h3>
<p>&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">[x, y]</span>)</span>{
  <span class="hljs-keyword">return</span> x + y;
}

add([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>]); <span class="hljs-comment">// 3</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x51FD;&#x6570;<code>add</code>&#x7684;&#x53C2;&#x6570;&#x8868;&#x9762;&#x4E0A;&#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x4F46;&#x5728;&#x4F20;&#x5165;&#x53C2;&#x6570;&#x7684;&#x90A3;&#x4E00;&#x523B;&#xFF0C;&#x6570;&#x7EC4;&#x53C2;&#x6570;&#x5C31;&#x88AB;&#x89E3;&#x6784;&#x6210;&#x53D8;&#x91CF;<code>x</code>&#x548C;<code>y</code>&#x3002;&#x5BF9;&#x4E8E;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x4EE3;&#x7801;&#x6765;&#x8BF4;&#xFF0C;&#x5B83;&#x4EEC;&#x80FD;&#x611F;&#x53D7;&#x5230;&#x7684;&#x53C2;&#x6570;&#x5C31;&#x662F;<code>x</code>&#x548C;<code>y</code>&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x53E6;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript">[[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>]].map(([a, b]) =&gt; a + b);
<span class="hljs-comment">// [ 3, 7 ]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x610F;&#x601D;&#x662F;&#x5C06;&#x6BCF;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x5143;&#x7D20;&#x8FDB;&#x884C;&#x89E3;&#x6784;&#xFF0C;[a,b]=[1,2],[a,b]=[3,4],&#x8FD9;&#x6837;&#x7ED3;&#x679C;&#x5C31;&#x662F;[3,7].</p>
<h3 id="&#x4F7F;&#x7528;&#x573A;&#x666F;">&#x4F7F;&#x7528;&#x573A;&#x666F;</h3>
<h4 id="&#x4EA4;&#x6362;&#x53D8;&#x91CF;&#x7684;&#x503C;">&#x4EA4;&#x6362;&#x53D8;&#x91CF;&#x7684;&#x503C;</h4>
<p>&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x5728;&#x5F88;&#x591A;&#x65F6;&#x5019;&#x53EF;&#x4EE5;&#x5927;&#x5927;&#x7B80;&#x5316;&#x4EE3;&#x7801;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x4EA4;&#x6362;&#x4E24;&#x4E2A;&#x53D8;&#x91CF;<code>x</code>&#x548C;<code>y</code>&#x7684;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x8FD9;&#x4E48;&#x5199;&#xFF0C;&#x4E0D;&#x518D;&#x9700;&#x8981;&#x4E34;&#x65F6;&#x53D8;&#x91CF;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span>;
[x, y] = [y, x]
</code></pre>
<p>&#x5FEB;&#x901F;&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x9875;&#x9762;&#x7684;&#x57DF;&#x540D;&#x548C;&#x8DEF;&#x5F84;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> {hostname:domain, pathname:path} = location;
</code></pre>
<h4 id="&#x51FD;&#x6570;&#x53C2;&#x6570;&#x7684;&#x5B9A;&#x4E49;"><strong>&#x51FD;&#x6570;&#x53C2;&#x6570;&#x7684;&#x5B9A;&#x4E49;</strong></h4>
<p>&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x90A3;&#x4E48;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x89E3;&#x6784;&#x76F4;&#x63A5;&#x628A;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x7ED1;&#x5B9A;&#x5230;&#x53D8;&#x91CF;&#x4E2D;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x5FEB;&#x901F;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;<code>Date</code>&#x5BF9;&#x8C61;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">buildDate</span>(<span class="hljs-params">{year, month, day, hour=0, minute=0, second=0}</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(year + <span class="hljs-string">&apos;-&apos;</span> + month + <span class="hljs-string">&apos;-&apos;</span> + day + <span class="hljs-string">&apos; &apos;</span> + hour + <span class="hljs-string">&apos;:&apos;</span> + minute + <span class="hljs-string">&apos;:&apos;</span> + second);
}
</code></pre>
<p>&#x5B83;&#x7684;&#x65B9;&#x4FBF;&#x4E4B;&#x5904;&#x5728;&#x4E8E;&#x4F20;&#x5165;&#x7684;&#x5BF9;&#x8C61;&#x53EA;&#x9700;&#x8981;<code>year</code>&#x3001;<code>month</code>&#x548C;<code>day</code>&#x8FD9;&#x4E09;&#x4E2A;&#x5C5E;&#x6027;&#xFF1A;</p>
<pre><code class="lang-javascript">buildDate({ year: <span class="hljs-number">2017</span>, month: <span class="hljs-number">1</span>, day: <span class="hljs-number">1</span> });
<span class="hljs-comment">// Sun Jan 01 2017 00:00:00 GMT+0800 (CST)</span>
</code></pre>
<p>&#x4E5F;&#x53EF;&#x4EE5;&#x4F20;&#x5165;<code>hour</code>&#x3001;<code>minute</code>&#x548C;<code>second</code>&#x5C5E;&#x6027;&#xFF1A;</p>
<pre><code class="lang-javascript">buildDate({ year: <span class="hljs-number">2017</span>, month: <span class="hljs-number">1</span>, day: <span class="hljs-number">1</span>, hour: <span class="hljs-number">20</span>, minute: <span class="hljs-number">15</span> });
<span class="hljs-comment">// Sun Jan 01 2017 20:15:00 GMT+0800 (CST)</span>
</code></pre>
<p>&#x4F7F;&#x7528;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x53EF;&#x4EE5;&#x51CF;&#x5C11;&#x4EE3;&#x7801;&#x91CF;&#xFF0C;&#x4F46;&#x662F;&#xFF0C;&#x9700;&#x8981;&#x5728;&#x652F;&#x6301;ES6&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x7279;&#x6027;&#x7684;&#x73B0;&#x4EE3;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x624D;&#x80FD;&#x6B63;&#x5E38;&#x8FD0;&#x884C;&#x3002;&#x76EE;&#x524D;&#x652F;&#x6301;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x7684;&#x6D4F;&#x89C8;&#x5668;&#x5305;&#x62EC;Chrome&#xFF0C;Firefox&#xFF0C;Edge&#x7B49;&#x3002;</p>
<h4 id="&#x4ECE;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x591A;&#x4E2A;&#x503C;">&#x4ECE;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x591A;&#x4E2A;&#x503C;</h4>
<p>&#x51FD;&#x6570;&#x53EA;&#x80FD;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x8FD4;&#x56DE;&#x591A;&#x4E2A;&#x503C;&#xFF0C;&#x53EA;&#x80FD;&#x5C06;&#x5B83;&#x4EEC;&#x653E;&#x5728;&#x6570;&#x7EC4;&#x6216;&#x5BF9;&#x8C61;&#x91CC;&#x8FD4;&#x56DE;&#x3002;&#x6709;&#x4E86;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#xFF0C;&#x53D6;&#x51FA;&#x8FD9;&#x4E9B;&#x503C;&#x5C31;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
}
<span class="hljs-keyword">let</span> [a, b, c] = example();

<span class="hljs-comment">// &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">example</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> {
    foo: <span class="hljs-number">1</span>,
    bar: <span class="hljs-number">2</span>
  };
}
<span class="hljs-keyword">let</span> { foo, bar } = example();
</code></pre>
<h4 id="&#x63D0;&#x53D6;-json-&#x6570;&#x636E;"><strong>&#x63D0;&#x53D6; JSON &#x6570;&#x636E;</strong></h4>
<p>&#x89E3;&#x6784;&#x8D4B;&#x503C;&#x5BF9;&#x63D0;&#x53D6; JSON &#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x5C24;&#x5176;&#x6709;&#x7528;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> jsonData = {
  id: <span class="hljs-number">42</span>,
  status: <span class="hljs-string">&quot;OK&quot;</span>,
  data: [<span class="hljs-number">867</span>, <span class="hljs-number">5309</span>]
};

<span class="hljs-keyword">let</span> { id, status, data: number } = jsonData;

<span class="hljs-built_in">console</span>.log(id, status, number);
<span class="hljs-comment">// 42, &quot;OK&quot;, [867, 5309]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x5FEB;&#x901F;&#x63D0;&#x53D6; JSON &#x6570;&#x636E;&#x7684;&#x503C;&#x3002;</p>
<h4 id="&#x904D;&#x5386;map&#x7ED3;&#x6784;">&#x904D;&#x5386;Map&#x7ED3;&#x6784;</h4>
<p>&#x4EFB;&#x4F55;&#x90E8;&#x7F72;&#x4E86; Iterator &#x63A5;&#x53E3;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x90FD;&#x53EF;&#x4EE5;&#x7528;<code>for...of</code>&#x5FAA;&#x73AF;&#x904D;&#x5386;&#x3002;Map &#x7ED3;&#x6784;&#x539F;&#x751F;&#x652F;&#x6301; Iterator &#x63A5;&#x53E3;&#xFF0C;&#x914D;&#x5408;&#x53D8;&#x91CF;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;&#xFF0C;&#x83B7;&#x53D6;&#x952E;&#x540D;&#x548C;&#x952E;&#x503C;&#x5C31;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> map = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>();
map.set(<span class="hljs-string">&apos;first&apos;</span>, <span class="hljs-string">&apos;hello&apos;</span>);
map.set(<span class="hljs-string">&apos;second&apos;</span>, <span class="hljs-string">&apos;world&apos;</span>);

<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> [key, value] <span class="hljs-keyword">of</span> map) {
  <span class="hljs-built_in">console</span>.log(key + <span class="hljs-string">&quot; is &quot;</span> + value);
}
<span class="hljs-comment">// first is hello</span>
<span class="hljs-comment">// second is world</span>
</code></pre>
<p>&#x5982;&#x679C;&#x53EA;&#x60F3;&#x83B7;&#x53D6;&#x952E;&#x540D;&#xFF0C;&#x6216;&#x8005;&#x53EA;&#x60F3;&#x83B7;&#x53D6;&#x952E;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x5199;&#x6210;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x83B7;&#x53D6;&#x952E;&#x540D;</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> [key] <span class="hljs-keyword">of</span> map) {
  <span class="hljs-comment">// ...</span>
}

<span class="hljs-comment">// &#x83B7;&#x53D6;&#x952E;&#x503C;</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> [,value] <span class="hljs-keyword">of</span> map) {
  <span class="hljs-comment">// ...</span>
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="函数的扩展.html" class="navigation navigation-prev " aria-label="Previous page: 函数的扩展">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="函数3.html" class="navigation navigation-next " aria-label="Next page: 方法函数">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"变量作用域与解构赋值","level":"1.2.8.2","depth":3,"next":{"title":"方法函数","level":"1.2.8.3","depth":3,"path":"基础/函数3.md","ref":"基础/函数3.md","articles":[]},"previous":{"title":"函数的扩展","level":"1.2.8.1","depth":3,"path":"基础/函数的扩展.md","ref":"基础/函数的扩展.md","articles":[]},"dir":"ltr"},"config":{"plugins":["lunr","pageview-count","chapter-fold","back-to-top-button","code","hide-element","-sharing","sharing-plus","custom-favicon"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"code":{"copyButtons":true},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"favicon":"js.ico","back-to-top-button":{},"pageview-count":{},"custom-favicon":{},"sharing":{"qq":true,"all":["douban","facebook","google","instapaper","linkedin","twitter","weibo","messenger","qq","qzone","viber","whatsapp"],"douban":true,"facebook":true,"weibo":true,"twitter":true,"pocket":true,"google":true,"qzone":true},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Veng","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"JavaScript学习","language":"zh-hans","gitbook":"*","description":"javaScript的学习笔记"},"file":{"path":"基础/变量的解构赋值.md","mtime":"2020-12-10T02:10:04.990Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-12-10T03:00:51.663Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

